package com.example.myapplication.test;
import android.os.Bundle;
import android.util.Log;
import androidx.appcompat.app.AppCompatActivity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;

import androidx.appcompat.app.AppCompatActivity;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import com.example.myapplication.R;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.example.myapplication.mvp.home.HomeContract;
import com.example.myapplication.setting.SettingFragment;
import com.example.myapplication.test.SimpleAvtivity;
import com.example.myapplication.utils.DialogHelper;
import com.example.myapplication.utils.ScreenUtils;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

import static android.app.Activity.RESULT_OK;

import android.view.View;

import androidx.fragment.app.Fragment;
import androidx.appcompat.widget.Toolbar;

import android.Manifest;

import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import android.text.TextUtils;
import android.view.MenuItem;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.example.myapplication.Html5Activity;
import com.example.myapplication.R;
import com.example.myapplication.app.AppUtils;
import com.example.myapplication.app.Cache;
import com.example.myapplication.app.Url;
import com.example.myapplication.app.app;
import com.example.myapplication.data.beanv2.CourseGroup;
import com.example.myapplication.data.beanv2.UserWrapper;

import com.example.myapplication.mvp.add.AddActivity;
import com.example.myapplication.mvp.login.SignActivity;



import com.example.myapplication.utils.DialogHelper;
import com.example.myapplication.utils.DialogListener;
import com.example.myapplication.utils.RequestPermission;
import com.example.myapplication.utils.ScreenUtils;
import com.example.myapplication.utils.event.SignEvent;
import com.yzq.zxinglibrary.android.CaptureActivity;
import com.yzq.zxinglibrary.common.Constant;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.List;
import java.util.Objects;

import de.hdodenhof.circleimageview.CircleImageView;

import com.example.myapplication.setting.SettingActivity;

import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import androidx.appcompat.app.AppCompatActivity;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
public class getCountidp   extends AppCompatActivity{
    private static final String TAG = "MainActivity";
    private RedisClient redisClient;


    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.fragment_home);

        redisClient = new RedisClient("your_redis_host", 6379);

        new Thread(new Runnable() {
            @Override
            public void run() {
                String key = "api_limit";
                int rate = 1; // 每秒生成的令牌数
                int capacity = 5; // 令牌桶的容量
                int requested = 1; // 每次请求的令牌数

                while (true) {
                    boolean allowed = redisClient.requestToken(key, rate, capacity, requested);
                    if (allowed) {
                        Log.d(TAG, "Request allowed");
                    } else {
                        Log.d(TAG, "Request denied");
                    }
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }).start();
    }
}
